package com.neusoft.neuiotms.dcam.workflow.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.workflow.dto.JieyongConfrimSLDTO;
import com.neusoft.neuiotms.dcam.workflow.dto.JieyongSLDTO;
import com.neusoft.neuiotms.dcam.workflow.service.JieyongSLService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "总行借用工单")
@RestController
@RequestMapping(value = "/api/w/workflow/jieyongsl")
public class JieyongSLController {

    @Autowired
    private JieyongSLService jieyongSLService;

    @ApiOperation("新增资产产用申请")
    @PostMapping
    public ResultDTO<JieyongSLDTO> create(@RequestBody final JieyongSLDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.jieyongSLService.create(dto, user));
    }

    @ApiOperation("查看资产产用申请")
    @GetMapping("/{workOrderNum}/{taskId}")
    public ResultDTO<JieyongSLDTO> details(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.jieyongSLService.detail(workOrderNum, taskId, user));
    }

    @ApiOperation("确认")
    @PostMapping("confrim")
    public ResultListDTO<JieyongConfrimSLDTO> confrimCreate(@RequestBody final List<JieyongConfrimSLDTO> dtos,
            final UserBean user) {
        return ResultListDTO.success(this.jieyongSLService.confrimCreate(dtos, user));
    }

    @ApiOperation("查看确认")
    @GetMapping("confrim/{workOrderNum}/{taskId}")
    public ResultDTO<JieyongSLDTO> confrimDetails(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.jieyongSLService.confrimDetail(workOrderNum, taskId, user));
    }

    @ApiOperation("分发")
    @PostMapping("distribute")
    public ResultListDTO<JieyongConfrimSLDTO> distributeCreate(@RequestBody final List<JieyongConfrimSLDTO> dtos,
            final UserBean user) {
        return ResultListDTO.success(this.jieyongSLService.distributeCreate(dtos, user));
    }

    @ApiOperation("查看分发")
    @GetMapping("distribute/{workOrderNum}/{taskId}")
    public ResultDTO<JieyongSLDTO> distributeDetails(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.jieyongSLService.distributeDetail(workOrderNum, taskId, user));
    }

    @ApiOperation("分页查询入库单")
    @GetMapping("/p")
    public PageResultDTO<JieyongSLDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.jieyongSLService.search(pageable, searchable));
    }

    @ApiOperation("查看详情")
    @GetMapping("/{id}")
    public ResultDTO<JieyongSLDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.jieyongSLService.detail(id));
    }

}
